<script setup lang="ts">
import {onMounted, ref} from "vue";
import {userStatesStore} from "@/states/userSates.ts";
// import { showToast } from "vant/es";
import { useRouter } from "vue-router";
import { logout } from "@/api/login";
import { showToast } from "vant";

const router = useRouter()
const userStates = userStatesStore()
const user = ref()
onMounted(async () => {
  await userStates.getUserInfo()
  user.value = userStates.userInfo
})

// 修改
const setEmail = () => {
  showToast('该功能暂未完善，敬请期待！')
}
// 退出登录
const quitLogin = async () => {
  const res = await logout()
  if(res.data.code === 0){
    router.replace('/login')
    console.log(123)
    showToast('已退出登录')
  }else {
    showToast('系统错误'+res.data.description)
  }

}
</script>

<template>
  <template v-if="user">
    <van-cell title="修改电话" is-link to="/user/edit" :value="user.phone"  @click="setEmail()"/>
    <van-cell title="修改邮箱" is-link to="/user/edit" :value="user.email"  @click="setEmail()"/>
    <van-cell title="忘记密码" is-link to="/forget"/>
    <van-cell title="注册时间" :value="user.createTime" />
    <div class="quitLogin">
      <van-button type="primary" @click="quitLogin" plain style="width:  300px;" round>退出登录</van-button>
    </div>
  </template>
</template>

<style scoped>
.quitLogin {
  text-align:center;
  margin-top: 100px;
}
</style>import { showToast } from "vant";
